package com.myqm.controller.weixin;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.myqm.dto.ResultResponse;
import com.myqm.pojo.weixin.User;
import com.myqm.pojo.weixin.query.QueryUser;
import com.myqm.service.weixin.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "用户")
@RestController
@RequestMapping(value = "/weixin/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	@ApiOperation(value="新增记录")
	@PostMapping(value="/add")
	@ApiParam(required = true, value = "记录值")
	public ResultResponse<User> save(@Valid  @RequestBody User record) {
	    if(userService.save(record)<=0)
	        record=null;
	    else
	        record=userService.getById(record.getId());
		return new ResultResponse<User>(record);
	}
	
	@ApiOperation(value = "查询当前用户记录") 
	@PutMapping(value = "/get")
	public ResultResponse<User> getById() {
		return new ResultResponse<User>(userService.getUser());
	}
	
	@ApiParam(required = true , value = "记录内容")
	@PutMapping(value = "/edit") 
	public ResultResponse<User> editById(@Valid @RequestBody User record) {
		if(userService.edit(record)<=0)
	        record=null;
	    else
	        record=userService.getById(record.getId());
		return new ResultResponse<User>(record);
	}
}
